<?php
// +----------------------------------------------------------------------
// | 关键词表
// +----------------------------------------------------------------------

class keywords_model extends model {

	protected $url;

	public function _initialize() {
		$this->url = C('url');
	}

	//获取最热门关键字
	public function getHotKeywords($num='',$name=''){
		$num = $num ? $num : 10;
		$map = array();
		$map['search_num'] = array('gt',0);
		if($name && strlen($name)>=4) $map['_string'] = "match(name) against('$name')";
		$rows = $this->where($map)->order("rand()")->limit($num)->findAll();
		return $rows;
	}

	//设置关键词数据格式
	public function format($lists){
		if(empty($lists)) return array();
		foreach($lists as $k=>$v){
			$v['url'] = url('keyword',$v['name']);
			$lists[$k] = $v;
		}
		return $lists;
	}


}